print "run this"

inputFileName0 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3_phase0.txt.input.20121023"
inputFileHandler0 = open(inputFileName0,"r")

inputFileName1 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3_phase1.txt.input.20121023"
inputFileHandler1 = open(inputFileName1,"r")

inputFileName2 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3_phase2.txt.input.20121023"
inputFileHandler2 = open(inputFileName2,"r")
# Because there is an explanation line so I have to pass it
inputFileHandler2.readline()

outputFileName = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3_phase0_1_2.txt.output.20121023"
outputFileHandler = open(outputFileName,"w")


file0Lines = inputFileHandler0.readlines()
file2Lines = inputFileHandler2.readlines()

for index,line in enumerate(inputFileHandler1.readlines()):
    elementsFromFile1 = line.strip().split(" ")
    queryIDFromFile1 = elementsFromFile1[0]
    trecIDFromFile1 = elementsFromFile1[1]
    
    elementsFromFile0 = file0Lines[index].strip().split(" ")
    queryIDFromFile0 = elementsFromFile0[0]
    trecIDFromFile0 = elementsFromFile0[1]
    
    elementsFromFile2 = file2Lines[index].strip().split(" ")
    queryIDFromFile2 = elementsFromFile2[0]
    trecIDFromFile2 = elementsFromFile2[1]
    
    
    outputLine = ""    
    outputLine += elementsFromFile0[0] + " " + elementsFromFile0[1] + " " + elementsFromFile0[2] + " " + elementsFromFile0[3] + " " + elementsFromFile0[-8] + " " + elementsFromFile0[-7] + " " + elementsFromFile0[-6] + " " + elementsFromFile0[-5] + " " + elementsFromFile0[-4] + " " + elementsFromFile0[-3] + " " + elementsFromFile0[-2] + " "
    
    for index,element in enumerate(elementsFromFile1):
        if index != 0 and index != 1:
            outputLine += elementsFromFile1[index] + " "

    for index,element in enumerate(elementsFromFile2):
        if index != 0 and index != 1:
            outputLine += elementsFromFile2[index] + " "
            
    outputLine += elementsFromFile0[-1]
    
    outputFileHandler.write(outputLine.strip() + "\n")
    

outputFileHandler.close() 
    

